[REF] stock_landed_costs: usability changes

- update label for account_journal_id
- remove cost lines explanation
- label of the LC name
- remove former cost per unit
- auto compute cost line when validating
- rename former cost into original value
- remove additional landed cost form the tree view
- stock_landed_costs: rename cost line into additional costs
- add a final value field (Lucky day: the field I had to add was already
  defined but not used.)
- use monetary field
- make weight and volume optional
- journal entry visible only if posted
- landed costs wording in settings
- raise of no transfers are defined before validating

task-59011
This commit is contained in:
Simon Lejeune
2019-08-07 14:11:21 +00:00
parent b8f963a5e9
commit bc628b320d
3 changed files with 23 additions and 26 deletions
@@ -7,7 +7,7 @@
<field name="inherit_id" ref="stock.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="production_lot_info" position="after">
<h2>Costing</h2>
<h2>Valuation</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box" title="Affect landed costs on reception operations and split them among products to update their cost price.">
<div class="o_setting_left_pane">
@@ -16,7 +16,7 @@
<div class="o_setting_right_pane">
<label for="module_stock_landed_costs"/>
<div class="text-muted">
Include landed costs in product cost
Add additional cost (transport, customs, ...) in the value of the product.
</div>
<div class="content-group">
<div name="landed_cost_info"/>
@@ -48,6 +48,9 @@ class LandedCost(models.Model):
company_id = fields.Many2one('res.company', string="Company",
related='account_journal_id.company_id', readonly=False)
stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'stock_landed_cost_id')
vendor_bill_id = fields.Many2one(
'account.move', 'Vendor Bill', copy=False, domain=[('type', '=', 'in_invoice')])
currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
@api.depends('cost_lines.price_unit')
def _compute_total_amount(self):
@@ -78,8 +81,11 @@ class LandedCost(models.Model):
def button_validate(self):
if any(cost.state != 'draft' for cost in self):
raise UserError(_('Only draft landed costs can be validated'))
if any(not cost.valuation_adjustment_lines for cost in self):
raise UserError(_('No valuation adjustments lines. You should maybe recompute the landed costs.'))
if not all(cost.picking_ids for cost in self):
raise UserError(_('Please define the transfers on which those additional costs should apply.'))
cost_without_adjusment_lines = self.filtered(lambda c: not c.valuation_adjustment_lines)
if cost_without_adjusment_lines:
cost_without_adjusment_lines.compute_landed_cost()
if not self._check_sum():
raise UserError(_('Cost and adjustments lines do not match. You should maybe recompute the landed costs.'))
@@ -282,16 +288,14 @@ class AdjustmentLines(models.Model):
volume = fields.Float(
'Volume', default=1.0)
former_cost = fields.Float(
'Former Cost', digits='Product Price')
former_cost_per_unit = fields.Float(
'Former Cost(Per Unit)', compute='_compute_former_cost_per_unit',
digits=0, store=True)
'Original Value', digits='Product Price')
additional_landed_cost = fields.Float(
'Additional Landed Cost',
digits='Product Price')
final_cost = fields.Float(
'Final Cost', compute='_compute_final_cost',
'New Value', compute='_compute_final_cost',
digits=0, store=True)
currency_id = fields.Many2one('res.currency', related='cost_id.company_id.currency_id')
@api.depends('cost_line_id.name', 'product_id.code', 'product_id.name')
def _compute_name(self):
@@ -299,11 +303,6 @@ class AdjustmentLines(models.Model):
name = '%s - ' % (line.cost_line_id.name if line.cost_line_id else '')
line.name = name + (line.product_id.code or line.product_id.name or '')
@api.depends('former_cost', 'quantity')
def _compute_former_cost_per_unit(self):
for line in self:
line.former_cost_per_unit = line.former_cost / (line.quantity or 1.0)
@api.depends('former_cost', 'additional_landed_cost')
def _compute_final_cost(self):
for line in self:
@@ -20,7 +20,7 @@
attrs="{'invisible': [('state', 'not in', ['done'])]}" />
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<label for="name" class="oe_edit_only" string="Landed Cost"/>
<h1>
<field name="name" placeholder="Landed Cost Name"/>
</h1>
@@ -31,15 +31,13 @@
<field name="picking_ids" widget="many2many_tags" options="{'no_create_edit': True}" domain="[('state', '=', 'done'), ('picking_type_code', '!=', 'internal')]"/>
</group>
<group>
<field name="account_journal_id"/>
<field name="account_move_id"/>
<label for="account_journal_id" string="Journal"/>
<field name="account_journal_id" nolabel="1"/>
<field name="account_move_id" attrs="{'invisible': [('account_move_id', '=', False)]}"/>
</group>
</group>
<p class="oe_grey">
Landed cost are computed based on the purchase unit of measure.
</p>
<notebook>
<page string="Cost Lines">
<page string="Additional Costs">
<field name="cost_lines">
<form string="Cost Lines">
<group>
@@ -89,12 +87,12 @@
<tree string="Valuation Adjustments" editable="bottom" create="0">
<field name="cost_line_id" readonly="1"/>
<field name="product_id" readonly="1"/>
<field name="weight" readonly="1"/>
<field name="volume" readonly="1"/>
<field name="weight" readonly="1" optional="hide"/>
<field name="volume" readonly="1" optional="hide"/>
<field name="quantity" readonly="1"/>
<field name="former_cost_per_unit" readonly="1" widget="monetary"/>
<field name="former_cost" readonly="1"/>
<field name="additional_landed_cost"/>
<field name="currency_id" invisible="1"/>
<field name="former_cost" readonly="1" widget="monetary"/>
<field name="final_cost" readonly="1" widget="monetary"/>
</tree>
</field>
</page>