diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 8770b232808..12670d8e841 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1027,8 +1027,10 @@ class AccountInvoice(models.Model): if to_open_invoices.filtered(lambda inv: not inv.account_id): raise UserError(_('No account was found to create the invoice, be sure you have installed a chart of account.')) to_open_invoices.action_date_assign() + to_open_invoices._set_name_and_date_invoice() + res = to_open_invoices.action_move_create() to_open_invoices.invoice_validate() - return to_open_invoices.action_move_create() + return res @api.multi def action_invoice_paid(self): @@ -1440,29 +1442,9 @@ class AccountInvoice(models.Model): for invoice in self: vals = {'state': 'open'} - if not invoice.date_invoice: - vals['date_invoice'] = fields.Date.context_today(self) if not invoice.date_due: vals['date_due'] = vals.get('date_invoice', invoice.date_invoice) - if (invoice.move_name and invoice.move_name != '/'): - new_name = invoice.move_name - else: - new_name = False - journal = invoice.journal_id - if journal.sequence_id: - # If invoice is actually refund and journal has a refund_sequence then use that one or use the regular one - sequence = journal.sequence_id - if invoice.type in ['out_refund', 'in_refund'] and journal.refund_sequence: - if not journal.refund_sequence_id: - raise UserError(_('Please define a sequence for the credit notes')) - sequence = journal.refund_sequence_id - - new_name = sequence.with_context(ir_sequence_date=invoice.date or invoice.date_invoice).next_by_id() - else: - raise UserError(_('Please define a sequence on the journal.')) - #give the invoice its number directly as it's needed in _get_computed_reference() - invoice.number = new_name # Auto-compute reference, if not already existing and if configured on company if not invoice.reference and invoice.type == 'out_invoice': @@ -1816,6 +1798,29 @@ class AccountInvoice(models.Model): ('_onchange_journal_id', ['currency_id']), ]) + def _set_name_and_date_invoice(self): + for invoice in self: + if (invoice.move_name and invoice.move_name != '/'): + new_name = invoice.move_name + else: + new_name = False + journal = invoice.journal_id + if journal.sequence_id: + # If invoice is actually refund and journal has a refund_sequence then use that one or use the regular one + sequence = journal.sequence_id + if invoice.type in ['out_refund', 'in_refund'] and journal.refund_sequence: + if not journal.refund_sequence_id: + raise UserError(_('Please define a sequence for the credit notes')) + sequence = journal.refund_sequence_id + + new_name = sequence.with_context(ir_sequence_date=invoice.date or invoice.date_invoice).next_by_id() + else: + raise UserError(_('Please define a sequence on the journal.')) + #give the invoice its number directly as it's needed in _get_computed_reference() + invoice.number = new_name + if not invoice.date_invoice: + invoice.date_invoice = fields.Date.context_today(self) + class AccountInvoiceLine(models.Model): _name = "account.invoice.line" diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv index 27828b3824c..467a9af3fb5 100644 --- a/addons/account/security/ir.model.access.csv +++ b/addons/account/security/ir.model.access.csv @@ -2,7 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_product_product_account_user,product.product.account.user,product.model_product_product,group_account_user,1,0,0,0 access_product_product_account_manager,product.product.account.manager,product.model_product_product,account.group_account_manager,1,1,1,1 access_product_template_account_manager,product.template.account.manager,product.model_product_template,account.group_account_manager,1,1,1,1 -access_product_price_history_account_manager,product.price.history.account.manager,product.model_product_price_history,account.group_account_manager,1,1,1,1 access_account_payment_term,account.payment.term,model_account_payment_term,account.group_account_user,1,0,0,0 access_account_payment_term_line,account.payment.term.line,model_account_payment_term_line,account.group_account_user,1,0,0,0 access_account_account_type_manager,account.account.type,model_account_account_type,account.group_account_manager,1,1,1,1 diff --git a/addons/event_sale/security/ir.model.access.csv b/addons/event_sale/security/ir.model.access.csv index 87433e49dcf..c8ea33e6655 100644 --- a/addons/event_sale/security/ir.model.access.csv +++ b/addons/event_sale/security/ir.model.access.csv @@ -3,4 +3,3 @@ access_event_event_ticket_user,event.event.ticket.user,event_sale.model_event_ev access_event_event_ticket_admin,event.event.ticket.admin,event_sale.model_event_event_ticket,event.group_event_manager,1,1,1,1 access_product_template_event_manager,product.template.event.manager,product.model_product_template,event.group_event_manager,1,1,1,1 access_product_product_event_manager,product.product.event.manager,product.model_product_product,event.group_event_manager,1,1,1,1 -access_product_price_history_event_manager,product.price.history.event.manager,product.model_product_price_history,event.group_event_manager,1,1,1,1 diff --git a/addons/mrp/security/ir.model.access.csv b/addons/mrp/security/ir.model.access.csv index ab595d23776..7bb417338a7 100644 --- a/addons/mrp/security/ir.model.access.csv +++ b/addons/mrp/security/ir.model.access.csv @@ -24,7 +24,6 @@ access_stock_warehouse,stock.warehouse mrp_worker,stock.model_stock_warehouse,mr access_mrp_production_stock_worker,mrp.production stock_worker,model_mrp_production,stock.group_stock_user,1,0,0,0 access_product_product_user,product.product user,product.model_product_product,mrp.group_mrp_user,1,0,0,0 access_product_template_user,product.template user,product.model_product_template,mrp.group_mrp_user,1,0,0,0 -access_product_price_history_mrp_manager,product.price.history.mrp.manager,product.model_product_price_history,mrp.group_mrp_manager,1,1,1,1 access_uom_uom_user,uom.uom user,uom.model_uom_uom,mrp.group_mrp_user,1,0,0,0 access_product_supplierinfo_user,product.supplierinfo user,product.model_product_supplierinfo,mrp.group_mrp_user,1,1,1,1 access_res_partner,res.partner,base.model_res_partner,mrp.group_mrp_user,1,0,0,0 diff --git a/addons/mrp_account/__manifest__.py b/addons/mrp_account/__manifest__.py index f16c781339f..3203525413e 100644 --- a/addons/mrp_account/__manifest__.py +++ b/addons/mrp_account/__manifest__.py @@ -21,7 +21,10 @@ If the automated inventory valuation is active, the necessary accounting entries 'depends': ['mrp', 'stock_account'], "init_xml" : [], "demo_xml" : [], - "data": ["views/product_views.xml"], + "data": [ + "views/product_views.xml", + "views/mrp_production_views.xml", + ], 'installable': True, 'auto_install': True, } diff --git a/addons/mrp_account/models/mrp_production.py b/addons/mrp_account/models/mrp_production.py index 2b42f62318e..4a2d0f52a29 100644 --- a/addons/mrp_account/models/mrp_production.py +++ b/addons/mrp_account/models/mrp_production.py @@ -32,8 +32,7 @@ class MrpProduction(models.Model): if finished_move.product_id.cost_method in ('fifo', 'average'): qty_done = finished_move.product_uom._compute_quantity(finished_move.quantity_done, finished_move.product_id.uom_id) extra_cost = self.extra_cost * qty_done - finished_move.price_unit = (sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost) / qty_done - finished_move.value = sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost + finished_move.price_unit = (sum([-m.stock_valuation_layer_ids.value for m in consumed_moves]) + work_center_cost + extra_cost) / qty_done return True def _prepare_wc_analytic_line(self, wc_line): @@ -69,3 +68,10 @@ class MrpProduction(models.Model): res = super(MrpProduction, self).button_mark_done() self._costs_generate() return res + + def action_view_stock_valuation_layers(self): + self.ensure_one() + domain = [('id', 'in', (self.move_raw_ids + self.move_finished_ids).stock_valuation_layer_ids.ids)] + action = self.env.ref('stock_account.stock_valuation_layer_action').read()[0] + return dict(action, domain=domain) + diff --git a/addons/mrp_account/tests/test_mrp_account.py b/addons/mrp_account/tests/test_mrp_account.py index 19ab942abb7..ed35c0da1ff 100644 --- a/addons/mrp_account/tests/test_mrp_account.py +++ b/addons/mrp_account/tests/test_mrp_account.py @@ -83,7 +83,7 @@ class TestMrpAccount(common.TransactionCase): produce_wizard = produce_form.save() produce_wizard.do_produce() production_table.post_inventory() - move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").value + move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").stock_valuation_layer_ids.value # 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost) self.assertEqual(move_value, 141, 'Thing should have the correct price') diff --git a/addons/mrp_account/views/mrp_production_views.xml b/addons/mrp_account/views/mrp_production_views.xml new file mode 100644 index 00000000000..1ac5394ca3e --- /dev/null +++ b/addons/mrp_account/views/mrp_production_views.xml @@ -0,0 +1,15 @@ + + + mrp.production.view.inherited + mrp.production + + + +