Browse Source

[FIX] Bug Fixed 'stock_last_purchase_price'

pull/165/head
Ajmal JK 5 years ago
parent
commit
2a9057549e
  1. 4
      stock_last_purchase_price/__manifest__.py
  2. 69
      stock_last_purchase_price/models/product.py

4
stock_last_purchase_price/__manifest__.py

@ -22,7 +22,7 @@
{ {
'name': 'Costing method: Last Purchase Price', 'name': 'Costing method: Last Purchase Price',
'version': '13.0.1.0.0', 'version': '13.0.1.0.1',
'category': 'Inventory', 'category': 'Inventory',
'summary': "Introducing new costing method in Odoo 'last purchase price'", 'summary': "Introducing new costing method in Odoo 'last purchase price'",
'author': 'Cybrosys Techno solutions', 'author': 'Cybrosys Techno solutions',
@ -34,7 +34,7 @@
'stock_account', 'stock_account',
'purchase' 'purchase'
], ],
'images': ['static/description/banner.png'], 'images': ['static/description/banner.jpg'],
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': False, 'application': False,
'installable': True, 'installable': True,

69
stock_last_purchase_price/models/product.py

@ -50,7 +50,6 @@ class ProductTemplate(models.Model):
class ProductProduct(models.Model): class ProductProduct(models.Model):
_inherit = 'product.product' _inherit = 'product.product'
def create_price_change_account_move(self, new_price, account_id, company_id, origin): def create_price_change_account_move(self, new_price, account_id, company_id, origin):
""" """
""" """
@ -58,40 +57,39 @@ class ProductProduct(models.Model):
product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in self} product_accounts = {product.id: product.product_tmpl_id.get_product_accounts() for product in self}
for product in self.with_context().filtered(lambda r: r.valuation == 'real_time'): for product in self.with_context().filtered(lambda r: r.valuation == 'real_time'):
diff = product.standard_price - new_price diff = product.standard_price - new_price
if float_is_zero(diff, precision_rounding=product.currency_id.rounding): if not float_is_zero(diff, precision_rounding=product.currency_id.rounding):
raise UserError(_("No difference between the standard price and the new price.")) if not product_accounts[product.id].get('stock_valuation', False):
if not product_accounts[product.id].get('stock_valuation', False): raise UserError(_('You don\'t have any stock valuation account defined on your product category. You must define one before processing this operation.'))
raise UserError(_('You don\'t have any stock valuation account defined on your product category. You must define one before processing this operation.')) qty_available = product.qty_available
qty_available = product.qty_available if qty_available:
if qty_available: # Accounting Entries
# Accounting Entries if diff * qty_available > 0:
if diff * qty_available > 0: debit_account_id = account_id
debit_account_id = account_id credit_account_id = product_accounts[product.id]['stock_valuation'].id
credit_account_id = product_accounts[product.id]['stock_valuation'].id else:
else: debit_account_id = product_accounts[product.id]['stock_valuation'].id
debit_account_id = product_accounts[product.id]['stock_valuation'].id credit_account_id = account_id
credit_account_id = account_id
move_vals = {
move_vals = { 'journal_id': product_accounts[product.id]['stock_journal'].id,
'journal_id': product_accounts[product.id]['stock_journal'].id, 'company_id': company_id,
'company_id': company_id, 'ref': product.default_code,
'ref': product.default_code, 'line_ids': [(0, 0, {
'line_ids': [(0, 0, { 'name': _('%s changed cost from %s to %s - %s') % (origin, product.standard_price, new_price, product.display_name),
'name': _('%s changed cost from %s to %s - %s') % (origin, product.standard_price, new_price, product.display_name), 'account_id': debit_account_id,
'account_id': debit_account_id, 'debit': abs(diff * qty_available),
'debit': abs(diff * qty_available), 'credit': 0,
'credit': 0, 'product_id': product.id,
'product_id': product.id, }), (0, 0, {
}), (0, 0, { 'name': _('%s changed cost from %s to %s - %s') % (origin, product.standard_price, new_price, product.display_name),
'name': _('%s changed cost from %s to %s - %s') % (origin, product.standard_price, new_price, product.display_name), 'account_id': credit_account_id,
'account_id': credit_account_id, 'debit': 0,
'debit': 0, 'credit': abs(diff * qty_available),
'credit': abs(diff * qty_available), 'product_id': product.id,
'product_id': product.id, })],
})], }
} move = AccountMove.create(move_vals)
move = AccountMove.create(move_vals) move.post()
move.post()
return True return True
@ -115,7 +113,6 @@ class ProductProduct(models.Model):
else: else:
query = query % ('',) query = query % ('',)
self.env.cr.execute(query, params=params) self.env.cr.execute(query, params=params)
res = self.env.cr.fetchall() res = self.env.cr.fetchall()
for row in res: for row in res:
fifo_automated_values[(row[0], row[1])] = (row[2], row[3], list(row[4])) fifo_automated_values[(row[0], row[1])] = (row[2], row[3], list(row[4]))

Loading…
Cancel
Save