[IMP] stock_account: Counter-Part Account

In commit 40bd4a2f05, the counter-part account is made selectable and
required when changing the price of a product.

However, the same wizard is reused for the "Compute from BOM" feature,
in module `product_extended`. This forces the user to set an account
even if the product valuation is not "Perpetual (automated)".

In this commit, the field becomes required only if the product valuation
is "Perpetual (automated)".

opw-697866
This commit is contained in:
Nicolas Martinelli
2017-01-16 08:35:35 +01:00
parent cd45a1acb4
commit dfd5cf9563
2 changed files with 7 additions and 3 deletions
@@ -16,7 +16,8 @@ class StockChangeStandardPrice(models.TransientModel):
"If cost price is decreased, stock variation account will be creadited and stock input account will be debited.")
counterpart_account_id = fields.Many2one(
'account.account', string="Counter-Part Account",
domain=[('deprecated', '=', False)], required=True)
domain=[('deprecated', '=', False)])
counterpart_account_id_required = fields.Boolean(string="Counter-Part Account Required")
@api.model
def default_get(self, fields):
@@ -27,6 +28,7 @@ class StockChangeStandardPrice(models.TransientModel):
res['new_price'] = product_or_template.standard_price
if 'counterpart_account_id' in fields and 'counterpart_account_id' not in res:
res['counterpart_account_id'] = product_or_template.property_account_expense_id.id or product_or_template.categ_id.property_account_expense_categ_id.id
res['counterpart_account_id_required'] = bool(product_or_template.valuation == 'real_time')
return res
@api.multi
@@ -7,12 +7,14 @@
<field name="arch" type="xml">
<form string="Change Standard Price">
<separator string="Change Price"/>
<field name="counterpart_account_id_required" invisible="1"/>
<group>
<group>
<field name="new_price" string="Cost"/>
</group>
<group>
<field name="counterpart_account_id"/>
<field name="counterpart_account_id"
attrs="{'invisible': [('counterpart_account_id_required', '=', False)], 'required': [('counterpart_account_id_required', '=', True)]}"/>
</group>
</group>
<footer>
@@ -34,4 +36,4 @@
</record>
</data>
</odoo>
</odoo>