first commit
This commit is contained in:
2
modules/account_stock_landed_cost_weight/__init__.py
Normal file
2
modules/account_stock_landed_cost_weight/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
40
modules/account_stock_landed_cost_weight/account.py
Normal file
40
modules/account_stock_landed_cost_weight/account.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# 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 trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class LandedCost(metaclass=PoolMeta):
|
||||
__name__ = 'account.landed_cost'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.allocation_method.selection.append(('weight', 'By Weight'))
|
||||
|
||||
def allocate_cost_by_weight(self):
|
||||
self.factors = self._get_factors('weight')
|
||||
self._allocate_cost(self.factors)
|
||||
|
||||
def unallocate_cost_by_weight(self):
|
||||
factors = self.factors or self._get_factors('weight')
|
||||
self._allocate_cost(factors, sign=-1)
|
||||
|
||||
def _get_weight_factors(self):
|
||||
"Return the factor for each move based on weight"
|
||||
moves = self.stock_moves()
|
||||
sum_weight = Decimal(0)
|
||||
weights = {}
|
||||
for move in moves:
|
||||
weight = Decimal(str(move.internal_weight or 0))
|
||||
weights[move.id] = weight
|
||||
sum_weight += weight
|
||||
factors = {}
|
||||
length = Decimal(len(moves))
|
||||
for move in moves:
|
||||
if not sum_weight:
|
||||
factors[str(move.id)] = 1 / length
|
||||
else:
|
||||
factors[str(move.id)] = weights[move.id] / sum_weight
|
||||
return factors
|
||||
7
modules/account_stock_landed_cost_weight/locale/bg.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/bg.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/ca.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/ca.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per pes"
|
||||
7
modules/account_stock_landed_cost_weight/locale/cs.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/cs.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/de.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/de.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Nach Gewicht"
|
||||
7
modules/account_stock_landed_cost_weight/locale/es.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/es.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Por peso"
|
||||
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/et.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/et.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Kaalu järgi"
|
||||
7
modules/account_stock_landed_cost_weight/locale/fa.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/fa.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "براساس وزن"
|
||||
7
modules/account_stock_landed_cost_weight/locale/fi.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/fi.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/fr.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/fr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Par poids"
|
||||
7
modules/account_stock_landed_cost_weight/locale/hu.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/hu.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/id.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/id.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/it.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/it.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per peso"
|
||||
7
modules/account_stock_landed_cost_weight/locale/lo.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/lo.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "ດ້ວຍນໍ້າໜັກ"
|
||||
7
modules/account_stock_landed_cost_weight/locale/lt.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/lt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Pagal svorį"
|
||||
7
modules/account_stock_landed_cost_weight/locale/nl.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/nl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per Gewicht"
|
||||
7
modules/account_stock_landed_cost_weight/locale/pl.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/pl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Wg wagi"
|
||||
7
modules/account_stock_landed_cost_weight/locale/pt.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/pt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Por Peso"
|
||||
7
modules/account_stock_landed_cost_weight/locale/ro.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/ro.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "După Greutate"
|
||||
7
modules/account_stock_landed_cost_weight/locale/ru.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/ru.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/sl.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/sl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Po teži"
|
||||
7
modules/account_stock_landed_cost_weight/locale/tr.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/tr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/uk.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/uk.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/account_stock_landed_cost_weight/locale/zh_CN.po
Normal file
7
modules/account_stock_landed_cost_weight/locale/zh_CN.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:account.landed_cost,allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "基于重量"
|
||||
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,193 @@
|
||||
================================
|
||||
Account Stock Landed Cost Weight
|
||||
================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_stock_landed_cost_weight', create_company, create_chart)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> payable = accounts['payable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> account_tax = accounts['tax']
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('300')
|
||||
>>> template.cost_price_method = 'average'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.weight_uom = kg
|
||||
>>> template.weight = 20
|
||||
>>> product1, = template.products
|
||||
>>> product1.cost_price = Decimal('80')
|
||||
>>> template.save()
|
||||
>>> product1, = template.products
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('200')
|
||||
>>> template.cost_price_method = 'average'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.weight_uom = kg
|
||||
>>> template.weight = 10
|
||||
>>> product2, = template.products
|
||||
>>> product2.cost_price = Decimal('50')
|
||||
>>> template.save()
|
||||
>>> product2, = template.products
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Landed Cost'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.landed_cost = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> product_landed_cost, = template.products
|
||||
>>> product_landed_cost.cost_price = Decimal('10')
|
||||
>>> template.save()
|
||||
>>> product_landed_cost, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> input_loc, = Location.find([('code', '=', 'IN')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> PaymentTerm = Model.get('account.invoice.payment_term')
|
||||
>>> payment_term = PaymentTerm(name='Term')
|
||||
>>> line = payment_term.lines.new(type='remainder')
|
||||
>>> payment_term.save()
|
||||
|
||||
Receive 10 unit of the product1 @ 100 and 10 unit of product2 @50::
|
||||
|
||||
>>> ShipmentIn = Model.get('stock.shipment.in')
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.planned_date = today
|
||||
>>> shipment.supplier = supplier
|
||||
>>> shipment.warehouse = warehouse_loc
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.product = product1
|
||||
>>> move.quantity = 10
|
||||
>>> move.from_location = supplier_loc
|
||||
>>> move.to_location = input_loc
|
||||
>>> move.unit_price = Decimal('100')
|
||||
>>> move.currency = company.currency
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.product = product2
|
||||
>>> move.quantity = 10
|
||||
>>> move.from_location = supplier_loc
|
||||
>>> move.to_location = input_loc
|
||||
>>> move.unit_price = Decimal('50')
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment.click('receive')
|
||||
>>> sorted([m.unit_price for m in shipment.incoming_moves])
|
||||
[Decimal('50'), Decimal('100')]
|
||||
|
||||
Invoice landed cost::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.type = 'in'
|
||||
>>> invoice.party = supplier
|
||||
>>> invoice.payment_term = payment_term
|
||||
>>> invoice.invoice_date = today
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product_landed_cost
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('30')
|
||||
>>> invoice.click('post')
|
||||
|
||||
Add landed cost::
|
||||
|
||||
>>> LandedCost = Model.get('account.landed_cost')
|
||||
>>> landed_cost = LandedCost()
|
||||
>>> shipment, = landed_cost.shipments.find([])
|
||||
>>> landed_cost.shipments.append(shipment)
|
||||
>>> invoice_line, = landed_cost.invoice_lines.find([])
|
||||
>>> landed_cost.invoice_lines.append(invoice_line)
|
||||
>>> landed_cost.allocation_method = 'weight'
|
||||
>>> landed_cost.save()
|
||||
>>> landed_cost.state
|
||||
'draft'
|
||||
>>> post_landed_cost = landed_cost.click('post_wizard')
|
||||
>>> post_landed_cost.form.cost
|
||||
Decimal('30.0000')
|
||||
>>> sorted([m.cost for m in post_landed_cost.form.moves])
|
||||
[Decimal('1.0000'), Decimal('2.0000')]
|
||||
>>> post_landed_cost.execute('post')
|
||||
>>> landed_cost.state
|
||||
'posted'
|
||||
|
||||
Check move unit price is 153::
|
||||
|
||||
>>> sorted([m.unit_price for m in shipment.incoming_moves])
|
||||
[Decimal('51.0000'), Decimal('102.0000')]
|
||||
|
||||
Cancel landed cost reset unit price::
|
||||
|
||||
>>> landed_cost.click('cancel')
|
||||
>>> landed_cost.state
|
||||
'cancelled'
|
||||
|
||||
>>> shipment.reload()
|
||||
>>> sorted([m.unit_price for m in shipment.incoming_moves])
|
||||
[Decimal('50.0000'), Decimal('100.0000')]
|
||||
@@ -0,0 +1,12 @@
|
||||
# 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 trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class AccountStockLandedCostTestCase(ModuleTestCase):
|
||||
'Test Account Stock Landed Cost module'
|
||||
module = 'account_stock_landed_cost'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -0,0 +1,8 @@
|
||||
# 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 trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
12
modules/account_stock_landed_cost_weight/tryton.cfg
Normal file
12
modules/account_stock_landed_cost_weight/tryton.cfg
Normal file
@@ -0,0 +1,12 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
account_stock_landed_cost
|
||||
ir
|
||||
product
|
||||
product_measurements
|
||||
stock_shipment_measurements
|
||||
|
||||
[register]
|
||||
model:
|
||||
account.LandedCost
|
||||
Reference in New Issue
Block a user