/usr/lib/python2.7/dist-packages/trytond/modules/account_stock_continental/product.py is in tryton-modules-account-stock-continental 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from decimal import Decimal
from functools import partial
from trytond.model import ModelView, fields
from trytond.wizard import Wizard, StateView, StateTransition, Button
from trytond.pyson import Eval, Get
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from trytond.modules.account_product import MissingFunction
__all__ = ['Category', 'Template', 'UpdateCostPriceAsk',
'UpdateCostPriceShowMove', 'UpdateCostPrice']
__metaclass__ = PoolMeta
class Category:
__name__ = 'product.category'
account_stock = fields.Property(fields.Many2One('account.account',
'Account Stock', domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_parent')),
},
depends=['account_parent']))
account_stock_supplier = fields.Property(fields.Many2One('account.account',
'Account Stock Supplier', domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_parent')),
},
depends=['account_parent']))
account_stock_customer = fields.Property(fields.Many2One('account.account',
'Account Stock Customer', domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_parent')),
},
depends=['account_parent']))
account_stock_production = fields.Property(
fields.Many2One('account.account',
'Account Stock Production', domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_parent')),
},
depends=['account_parent']))
account_stock_lost_found = fields.Property(fields.Many2One(
'account.account', 'Account Stock Lost and Found', domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_parent')),
},
depends=['account_parent']))
account_stock_used = MissingFunction(fields.Many2One('account.account',
'Account Stock Used'), 'missing_account', 'get_account')
account_stock_supplier_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Supplier Used'),
'missing_account', 'get_account')
account_stock_customer_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Customer Used'),
'missing_account', 'get_account')
account_stock_production_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Production Used'),
'missing_account', 'get_account')
account_stock_lost_found_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Lost and Found'),
'missing_account', 'get_account')
class Template:
__name__ = 'product.template'
account_stock = fields.Property(fields.Many2One('account.account',
'Account Stock',
domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_category')
| (Eval('type') != 'goods')),
}, help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
account_stock_supplier = fields.Property(fields.Many2One('account.account',
'Account Stock Supplier',
domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_category')
| (Eval('type') != 'goods')),
}, help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
account_stock_customer = fields.Property(fields.Many2One('account.account',
'Account Stock Customer',
domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_category')
| (Eval('type') != 'goods')),
}, help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
account_stock_production = fields.Property(
fields.Many2One('account.account',
'Account Stock Production',
domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_category')
| (Eval('type') != 'goods')),
}, help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
account_stock_lost_found = fields.Property(fields.Many2One(
'account.account', 'Account Stock Lost and Found',
domain=[
('kind', '=', 'stock'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}).get('company')
| Eval('account_category')
| (Eval('type') != 'goods')),
}, help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
account_stock_used = MissingFunction(fields.Many2One('account.account',
'Account Stock Used'), 'missing_account', 'get_account')
account_stock_supplier_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Supplier Used'),
'missing_account', 'get_account')
account_stock_customer_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Customer Used'),
'missing_account', 'get_account')
account_stock_production_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Production Used'),
'missing_account', 'get_account')
account_stock_lost_found_used = MissingFunction(fields.Many2One(
'account.account', 'Account Stock Lost and Found'),
'missing_account', 'get_account')
@classmethod
def __setup__(cls):
super(Template, cls).__setup__()
cls._modify_no_move.append(('cost_price', 'change_cost_price'))
cls._error_messages.update({
'change_cost_price': ('You cannot change the cost price for '
'a product which is associated to stock moves.\n'
'You must use the "Update Cost Price" wizard.'),
})
class UpdateCostPriceAsk(ModelView):
'Update Cost Price Ask'
__name__ = 'product.update_cost_price.ask'
template = fields.Many2One('product.template', 'Product', readonly=True,
states={
'invisible': ~Eval('template'),
})
product = fields.Many2One('product.product', 'Variant', readonly=True,
states={
'invisible': ~Eval('product'),
})
cost_price = fields.Numeric('Cost Price', required=True, digits=(16, 4))
class UpdateCostPriceShowMove(ModelView):
'Update Cost Price Show Move'
__name__ = 'product.update_cost_price.show_move'
price_difference = fields.Numeric('Price Difference', readonly=True,
digits=(16, 4))
amount = fields.Numeric('Amount', readonly=True,
digits=(16, Eval('currency_digits', 2)), depends=['currency_digits'])
currency_digits = fields.Integer('Currency Digits', readonly=True)
journal = fields.Many2One('account.journal', 'Journal', required=True)
stock_account = fields.Many2One('account.account', 'Stock Account',
readonly=True)
counterpart = fields.Many2One('account.account', 'Counterpart',
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('id', '!=', Eval('stock_account')),
],
depends=['stock_account'], required=True)
description = fields.Char('Description')
class UpdateCostPrice(Wizard):
'Update Cost Price'
__name__ = 'product.update_cost_price'
start_state = 'ask_price'
ask_price = StateView('product.update_cost_price.ask',
'account_stock_continental.update_cost_price_ask_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Ok', 'should_show_move', 'tryton-go-next', default=True),
])
should_show_move = StateTransition()
show_move = StateView('product.update_cost_price.show_move',
'account_stock_continental.update_cost_price_show_move_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Ok', 'create_move', 'tryton-ok', default=True),
])
create_move = StateTransition()
update_price = StateTransition()
@classmethod
def __setup__(cls):
super(UpdateCostPrice, cls).__setup__()
cls._error_messages.update({
'same_account': 'The stock account and the counterpart can '
'not be the same account',
})
def default_ask_price(self, fields):
context = Transaction().context
if ('product' in fields
and context['active_model'] == 'product.product'):
return {
'product': context['active_id'],
}
elif ('template' in fields
and context['active_model'] == 'product.template'):
return {
'template': context['active_id'],
}
else:
return {}
@staticmethod
def get_product():
'Return the product or template instance'
pool = Pool()
Product = pool.get('product.product')
ProductTemplate = pool.get('product.template')
context = Transaction().context
if context['active_model'] == 'product.product':
return Product(context['active_id'])
else:
return ProductTemplate(context['active_id'])
@classmethod
def get_quantity(cls):
pool = Pool()
Date = pool.get('ir.date')
Stock = pool.get('stock.location')
locations = Stock.search([('type', '=', 'storage')])
stock_date_end = Date.today()
with Transaction().set_context(locations=[l.id for l in locations],
stock_date_end=stock_date_end):
product = cls.get_product()
if hasattr(product.__class__, 'cost_price'):
return product.quantity
else:
return product.template.quantity
def transition_should_show_move(self):
if self.get_quantity() != 0:
return 'show_move'
return 'update_price'
def default_show_move(self, fields):
pool = Pool()
User = pool.get('res.user')
AccountConfiguration = pool.get('account.configuration')
product = self.get_product()
price_diff = (self.ask_price.cost_price
- product.cost_price)
user = User(Transaction().user)
amount = user.company.currency.round(
Decimal(str(self.get_quantity())) * price_diff)
stock_account_id = product.account_stock_used.id
config = AccountConfiguration(1)
stock_journal_id = config.stock_journal.id
counterpart_id = (config.cost_price_counterpart_account.id if
config.cost_price_counterpart_account else None)
return {
'journal': stock_journal_id,
'amount': amount,
'price_difference': price_diff,
'stock_account': stock_account_id,
'counterpart': counterpart_id,
'currency_digits': user.company.currency.digits,
}
def get_move_lines(self):
Line = Pool().get('account.move.line')
amount = self.show_move.amount
return [Line(
debit=amount if amount > 0 else 0,
credit=-amount if amount < 0 else 0,
account=self.show_move.stock_account,
),
Line(
debit=-amount if amount < 0 else 0,
credit=amount if amount > 0 else 0,
account=self.show_move.counterpart,
),
]
def get_move(self):
pool = Pool()
Date = pool.get('ir.date')
Period = pool.get('account.period')
User = pool.get('res.user')
Move = pool.get('account.move')
user = User(Transaction().user)
period_id = Period.find(user.company.id)
return Move(
description=self.show_move.description,
period=period_id,
journal=self.show_move.journal,
date=Date.today(),
origin=self.get_product(),
lines=self.get_move_lines(),
)
def transition_create_move(self):
Move = Pool().get('account.move')
if self.show_move.counterpart == self.show_move.stock_account:
self.raise_user_error('same_account')
move = self.get_move()
move.save()
Move.post([move])
return 'update_price'
def transition_update_price(self):
pool = Pool()
Product = pool.get('product.product')
ProductTemplate = pool.get('product.template')
if hasattr(Product, 'cost_price'):
write = partial(Product.write, [self.ask_price.product])
else:
if self.ask_price.template:
template = self.ask_price.template
else:
template = self.ask_price.product.template
write = partial(ProductTemplate.write, [template])
write({'cost_price': self.ask_price.cost_price})
return 'end'
|